;(function() {
		init_parsley();
		$("#in_varifycation_type").change(function(){
			if($(this).val()!=0){
				$('#in_varifycation').val(1);
			}else{
				$('#in_varifycation').val(0);
			}
		})
		//同步会员信息
		$("#btn-sync").click(function(){
			var card_no=$("#card_no").val();
			var mobile=$("#mobile").val();
			if(card_no==null||(card_no.trim().length<1)){
				toastr["error"]("卡号格式错误");
				return false;
			}else{
				loading();
				$.post(
					"/admin/member/get_member_info",
					{"card_no":card_no,"mobile":mobile},
					function(data){
						close_loading();
							 if(data.flag){
							  var result=data.data;
							 	$("#member_id").val(result.MemberID);
							 	$("#contract_id").val(result.ContractID);
							 	$("#mobile").val(result.Mobile);
							 	$("#name").val(result.MemberName);
							 	$("#start_date").val(result.StartDate);
							 	$("#end_date").val(result.EndDate);
							 	$("#contract_status").val(result.ContractStatus);
							 	$("#membership_type").val(result.MembershipType);
							 	$("#surplus_num").val(result.SurplusNum);
							 	$("#member_url").val(result.MemberUrl);
							 	toastr["success"]("成功");
							 }else{
							 	$("#member_id").val("");
							 	$("#contract_id").val("");
							 	$("#mobile").val("");
							 	$("#name").val("");
							 	$("#start_date").val("");
							 	$("#end_date").val("");
							 	$("#contract_status").val("");
							 	$("#membership_type").val("");
							 	$("#surplus_num").val("");
							 	$("#member_url").val("");
							 	toastr["error"](data.msg,"错误提示");
							 }
					}
				);
				close_loading();
				 return false;
			}
		})
		$(".btn_fingerprint").click(function(){
		    var step=$(this).attr("data-step");
		    if(step=="1"){
		    	sign_finger1();		    	
		    }else if(step==2){
		    	sign_finger2();
		    }else{
		    	toastr["error"]("无效的点击","错误提示");
		    	return false;
		    }
		});
		
		//获取人脸头像模板
		$(".btn_interface_url").click(function(){
			$.post(
				"/Admin/Member/get_face_code",
				{"card_no":$("#card_no").val(),"member_url":$("#member_url").val()},
				function(data){
					if(data.flag){
						$("#face_image1").attr("src",data.data.icon1);
						$("#icon1").val(data.data.icon1);	
						$("#face1").val(data.data.face1); 
						toastr['success']("接口获取头像成功"); 
						return false;
					}else{
						toastr['error'](data.msg); 
						return false;
					}
				}
			);
		})
		$(".btn_face_camare").click(function(){
			var step=$(this).attr("data-step");
			if(step=="1"){
				open_camare(0);
			}else if(step=="2"){
				var card_no=$("#card_no").val();
				if(card_no.length<1){
					toastr['error']("卡号不正确","操作失败！"); 
					return false;
				}
				var csharp=window.external;
				var faces= csharp.GetFaceCode(card_no);
				if(faces==null||faces.length<1000){
					toastr["error"]("模板不清晰，请重新拍摄");
					return false;
				}
				faces=faces.split(",");
				var arr=csharp.GetFaceUrl().split(",");
				if(arr.length==1){
					$("#face_image1").attr("src",arr[0]);
					$("#face_image2").attr("src","/data/finger/a8.jpg");
					$("#face_image3").attr("src","/data/finger/a8.jpg");
					$("#icon1").val(arr[0]);	
					$("#face1").val(faces[0]);
				}
				if(arr.length==2){
					$("#face_image1").attr("src",arr[0]);
					$("#face_image2").attr("src",arr[1]);
					$("#face_image3").attr("src","/data/finger/a8.jpg");
					$("#icon1").val(arr[0]+","+arr[1]);
					$("#face1").val(faces[0]+","+faces[1]);
				}
				if(arr.length==3){
					$("#face_image1").attr("src",arr[0]);
					$("#face_image2").attr("src",arr[1]);
					$("#face_image3").attr("src",arr[2]);
					$("#icon1").val(arr[0]+","+arr[1]+","+arr[2]);
					$("#face1").val(faces[0]+","+faces[1]+","+faces[2]);
				}
				
				
			}else{
				toastr["error"]("无效的点击");
			}
		   return false;											
		})
	   	$("#form-submit").click(function(){
	   		var flag=$('#validate-form').parsley('validate' );
	   		if(flag){
	   			
	   			var type=$("#membership_type").val();
	   			if(!(type==1||type==2||type==3||type==4)){
	   				toastr['error']("请先同步会员数据");
	   				return false;
	   			}
	   			if($("#in_varifycation").val()==1){//需要验证
	   				var varify_type=$("#in_varifycation_type").val();
		   			if(varify_type==1){// 指纹验证
		   				if($("#fingerprint").val().length<1000){
		   					toastr['error']("请录入指纹模板");
		   					return false;
		   				}
		   			}else if(varify_type==2){// 人脸验证
		   				if($("#face1").val().length<1000){
		   					toastr['error']("请录入人脸模板");
		   					return false;
		   				}
		   			}
	   			}
	   			loading();
	   			$.post(
	   				"/admin/member/add",
	   				$("#validate-form").serialize(),
	   				function(data){
	   					if($("#in_varifycation").val()==1){//需要验证
	   							var varify_type=$("#in_varifycation_type").val();
					   			if(varify_type==1){// 指纹验证
					   				write_txt_finger($("#card_no").val(),$("#fingerprint").val());
					   			}else if(varify_type==2){// 人脸验证					   				
					   				if($("#face1").val().indexOf("undefine")>=0){
										toastr['error']("模板包含undefine,请重新上传","操作失败！");
										close_loading();
										return false;
									}
					   					write_txt_face($("#card_no").val(),$("#face1").val());	
					   			}
	   					}
	   					
	   					close_loading();
			      		if(data.flag){
			      			$("#myModal").modal("hide");
			      			toastr['success']("操作成功！", ''); 
			      			$("#myform #btn-advanced-refresh").trigger("click");// 刷新页面
			      		}else{
			      		 	toastr['error'](data.msg,"操作失败！"); 
			      		}
	   				}
	   			);
	   		}
	   	})
	   	
})();
